﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Project56
{
    
    class ArrLib
    {
        static void Main() 
        {
            int[] Masiv = { 10, 123, 56, 34, 67, 12, 34, 89, 78 };

            Masiv = SelectionSort(Masiv);
            
            for (int i = 0; i < Masiv.Length; i++)
            {
                Console.WriteLine(Masiv[i]);
            }
        }

        //Metod vozvroshayushiy index maximalnogo chisla v masive.
        static int IndexOfMaxNum(int[] arr)
        {
            int index = 0;

            for (int i = 0; i < arr.Length; i++)
            {

                if (arr[0] < arr[i])
                {
                    arr[0] = arr[i];
                    index = i;
                }
            }
            return index;
        }


        //Metod vozvroshayushiy index minimalnogo chisla v masive.
        static int IndexOfMinNum(int[] arr)
        {
            int index = 0;

            for (int i = 0; i < arr.Length; i++)
            {
                
                if (arr[0] > arr[i])
                {
                    arr[0] = arr[i];
                    index = i;
                }
            }
            return index;
        }


        //Metod vozvroshayushiy sumu vseh chisel v masive.
        static int Sum(int[] arr)
        { 
            int sum=0;
            for (int i = 0; i < arr.Length; i++)
            {
                sum = sum + arr[i];
            }
            return sum;
        }

        ////Metod vozvrashayushiy maximalnoe chislo v masive.
        static int MaxNum(int[] arr)
        {
            for (int i = 0; i < arr.Length; i++)
            {
                if (arr[0] < arr[i])
                {
                    arr[0] = arr[i];
                }
            } return arr[0];
        }

        //Metod vozvroshayushiy minimalnoe chislo v masive.
        static int MinNum(int[] arr)
        {
            for (int i = 0; i < arr.Length; i++)
            {
                if (arr[0] > arr[i])
                {
                    arr[0] = arr[i];
                }
            } return arr[0];
 
        }
        //Metod poluchayushiy chislo i mesto starta vozvrashayushiy index pervogo chisla sovpadayushigo v masive
        static int FindFIndex(int[] arr, int chislo, int startindex)
        {
            int res = -1;//not found

            for (int i = startindex; i < arr.Length; i++)
            {
                if (arr[i] == chislo)
                {
                    res = i;
                    break; 
                }

            }

            return (res);
        }

        //Metod poluchayushiy chislo i mesto starta vozvrashayushiy index poslednego chisla sovpadayushigo v masive
        static int FindLIndex(int[] arr, int chislo, int startindex)
        {
            int res = -1;//not found

            for (int i = startindex; i < arr.Length; i++)
            {
                if (arr[i] == chislo)
                {
                    res = i;

                }

            }

            return (res);
        }
        // Metod poluchayushiy masiv chisel i fozvroshayushiy masiv znacheniy true v mestah gde bilo sovpadenie
        static bool[] FindAllIndexes(int[] arr, int chislo)
        {
            bool [] AllIndexes= new bool[arr.Length];

            for (int i =0; i<arr.Length; i++)
            {
                 if (arr[i] == chislo)
                 {
                     AllIndexes[i] = true;
                 }
            }

            return (AllIndexes);
        }

        // Metod polu4ayushiy masiv i vozvroshayushiy ego v obratnom poryadke

        static int[] ObratniyPoryadok(int[] arr)
        {
            int[] obratniyporyadok = new int[arr.Length];
            int j =0;
            for (int i = arr.Length - 1; i < 0; i--)
            {
                obratniyporyadok[i] = arr[j];
                j++;
            }
            return obratniyporyadok;
        }

        //Metod poluchaet masiv iz chisel i vozvroshaet masiv chisel otsorterovanih po vozrastaniyu
        static int[] BobleSortToHi(int[] arr)
        {
            for (int i = 0; i < arr.Length; i++)
            {
                for (int j = 0; j < arr.Length - 1; j++)
                {
                    if (arr[j] > arr[j + 1])
                    {
                        int hold = arr[j];
                       arr[j] = arr[j + 1];
                       arr[j + 1] = hold;
                    }
                }

            }
            return arr;
        }

        //Metod poluchaet masiv iz chisel i vozvroshaet masiv chisel otsorterovanih po ubivaniyu
        static int[] BobleSortToLow(int[] arr)
        {
            for (int i = 0; i < arr.Length; i++)
            {
                for (int j = 0; j < arr.Length - 1; j++)
                {
                    if (arr[j] < arr[j + 1])
                    {
                        int hold = arr[j];
                        arr[j] = arr[j + 1];
                        arr[j + 1] = hold;
                    }
                }

            }
            return arr;
        }

        //Sortirovka Masiva ot menshego k bolshemu
        static void StraightInsertionSort(int[] arr)
        {
            int element;
            int ic;
                        
            for (int i = 1; i < arr.Length; i++)            
            {
                element = arr[i];
                ic = i - 1;
                while (ic >= 0 && arr[ic] > element)
                {
                    arr[ic + 1] = arr[ic];                      
                    ic--;
                }
                arr[ic + 1] = element;               
            }
        }
        // Sortirovka masiva chisel viborom ot menshego k bolshemu
        static int[] SelectionSort(int[] arr)
        {
            int i, j;
            int min, temp;

            for (i = 0; i < arr.Length - 1; i++)
            {
                min = i;

                for (j = i + 1; j < arr.Length; j++)
                {
                    if (arr[j] < arr[min])
                    {
                        min = j;
                    }
                }

                temp = arr[i];
                arr[i] = arr[min];
                arr[min] = temp;
            }
            return arr;
        }

    }
}
